import 'package:flutter/material.dart';
import 'package:flutter_swiper_tv/flutter_swiper.dart';
import 'common_image.dart';

const List<String> defaultImages = [
  'http://ww3.sinaimg.cn/large/006y8mN6ly1g6e2tdgve1j30ku0bsn75.jpg',
  'http://ww3.sinaimg.cn/large/006y8mN6ly1g6e2whp87sj30ku0bstec.jpg',
  'http://ww3.sinaimg.cn/large/006y8mN6ly1g6e2tl1v3bj30ku0bs77z.jpg',
];
// 图片宽 750px 高 424px
// 设置图片的宽高(为了代码易于阅读)
const ImageWidth = 750.0;
const ImageHeight = 424.0;

class CommonSwipper extends StatelessWidget {
  final List<String> images;

  const CommonSwipper({Key? key, this.images = defaultImages}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var height = MediaQuery.of(context).size.width/ImageWidth*ImageHeight;
    return Container(
      height: height,
      child: Swiper(
      itemCount: defaultImages.length,
      itemBuilder: (BuildContext context, int index){
        return CommonImage(
          images[index],
          fit: BoxFit.fill,
        );
      },
      autoplay: true,
      pagination: new SwiperPagination(),
    ),
    );
  }
}